<!DOCTYPE html>
<link href="style/text.css" media="screen" rel="stylesheet" type="text/css"/>
<?php
function blogHere() {
    $postsdir = 'gnoui/posts';
    if (file_exists($postsdir) && is_dir($postsdir)) {
        echo "<section class=\"gnoui\">";
        $posts = glob($postsdir . '/*.txt');
        rsort($posts); //latest post first
        foreach($posts  as $file) {
            if (filesize($file) > 0) {
                $date = basename($file);
                echo "<h1 class=\"post-date\">" . substr($date,4,2) . "." . substr($date,6,2) . "." . substr($date,0,4) . "</h1>";
                if ($handle = fopen($file, "r")) {
                    if($post = fread($handle, filesize($file))) {
                        $lines = explode("\n", $post);
                        echo "<p class=\"post-content\">";
                        foreach ($lines as $line) {
                            echo $line . "<br/>";
                        }
                        echo "</p>";
                    }
                } else  {
                    die("A corrupted post?");
                }
            } //no else because empty file
        }
        echo "</section>";
    } else {
        die("No post directory");
    }
}
?>
